package com.baselib;


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.Socket;
import java.net.UnknownHostException;

public class SocketSend
{
	public static void main(String[] args)
	{
		String ip = "60.247.106.211";
		int port = 9999;
		char[] tmp = new char[20];
		try
		{
			Socket socket = new Socket(ip, port);
			OutputStream os = socket.getOutputStream();
			InputStream is = socket.getInputStream();
			BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(os));
			String line = "0000000000000003sid";
			bw.write(line);
			bw.flush();
			System.out.println("发送:"+line);
			
			BufferedReader br = new BufferedReader(new InputStreamReader(is));
			StringBuffer sb = new StringBuffer();
			int c;
			//System.out.println((char)br.read());
			while((c=br.read())!=-1){
				System.out.println(c);
				sb.append((char)c);
			}
			
			System.out.println(sb.toString());
			/*
			System.out.println(br.read(tmp,0,16));
			String header = new String(tmp,0,16);
			String n = header.substring(10);
			int l = Integer.parseInt(n);
			br.read(tmp,0,l);

			System.out.println(new String(tmp,0,l));			
			System.out.println("finished");
			*/
			/*
			if ((line = br.readLine()) != null)
			{
				sb.append(line);
			}
			*/
			System.out.println("返回:"+sb.toString());
			
			br.close();
			bw.close();
			socket.close();
		} catch (UnknownHostException e)
		{
			e.printStackTrace();
		} catch (IOException e)
		{
			e.printStackTrace();
		} 
	}
}




